home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr46 / vfwdk.zip / VFWSDK.ZIP / SAMPLES / BRAVADO / INITC.C < prev    next >
C/C++ Source or Header  |  1993-01-31  |  5KB  |  197 lines

  1. /****************************************************************************
  2.  *
  3.  *   initc.c
  4.  * 
  5.  *   LibMain and driver startup routines
  6.  *
  7.  *   Microsoft Video for Windows Sample Capture Driver
  8.  *   Chips & Technologies 9001 based frame grabbers.
  9.  *
  10.  *   Copyright (c) 1992-1993 Microsoft Corporation.  All Rights Reserved.
  11.  *
  12.  *    You have a royalty-free right to use, modify, reproduce and 
  13.  *    distribute the Sample Files (and/or any modified version) in 
  14.  *    any way you find useful, provided that you agree that 
  15.  *    Microsoft has no warranty obligations or liability for any 
  16.  *    Sample Application Files which are modified. 
  17.  *
  18.  ***************************************************************************/
  19.  
  20. #include <windows.h>
  21. #include <mmsystem.h>
  22. #include <msvideo.h>
  23. #include <msviddrv.h>
  24. #define VCAP_MAIN       // define this and strings will get defined!!!
  25. #include "ct.h"
  26. #include "debug.h"
  27.  
  28. /*****************************************************************************
  29.  
  30.     strings
  31.  
  32.  ****************************************************************************/ 
  33.  
  34. extern char gszDriverName[];
  35.  
  36. //#define BCODE _based(_segname("_CODE"))
  37.  
  38. // non-localized strings
  39.  
  40. #ifdef DEBUG
  41.     static char BCODE gszDebug[]    = "MMDebug";
  42. #endif
  43.  
  44.  
  45. static WORD FAR PASCAL GetWindowsVersionCorrectly()
  46. {
  47.     WORD w;
  48.  
  49.     w = LOWORD( GetVersion() );
  50.  
  51.     return (w << 8) | (w >> 8);
  52. }
  53.  
  54. void FAR PASCAL HardErrorMsgBox( WORD wStringId )
  55. {
  56.     char    szPname[MAXPNAMELEN];
  57.     char    szErrorBuffer[MAX_ERR_STRING]; // buffer for error messages
  58.  
  59.     //  Starting with Windows 3.1, it is ok to bring up a _hard system modal_
  60.     //  message box during LibInit.  In Windows 3.0, this will not work!
  61.     if ( GetWindowsVersionCorrectly() >= 0x30A )
  62.     {
  63.         LoadString(ghModule, IDS_VCAPPRODUCT, szPname, MAXPNAMELEN);
  64.         LoadString(ghModule, wStringId, szErrorBuffer, sizeof(szErrorBuffer));
  65.         MessageBox(NULL, szErrorBuffer, szPname, MB_OK|MB_SYSTEMMODAL|MB_ICONHAND);
  66.     }
  67. }
  68.  
  69.  
  70. //
  71. // Copy Hardware INI values to globals
  72. // Returns 1
  73. //
  74. int NEAR PASCAL InitSetConfiguration(LPDEVICE_INIT lpDI)
  75. {
  76.     gwBaseReg           = lpDI->wIOBase;
  77.     gbInt               = lpDI->bInterrupt;
  78.     wPCVideoAddress     = lpDI->wIOBase;
  79.     return 1;
  80. }
  81.  
  82. //
  83. // Checks that values in DEVICE_INIT are legal.  
  84. // Ideally, this would also do a non-destructive test for hardware.
  85. // Returns: 1 if OK, 0 if settings are bad.
  86. //
  87. int FAR PASCAL InitVerifyConfiguration(LPDEVICE_INIT lpDI)
  88. {
  89.     if (!ConfigCheckAllDeviceInitParms (lpDI))
  90.         return 0;
  91.  
  92.     return 1;
  93. }
  94.  
  95. //
  96. // Main entry point to initialize the device.  Call once only.
  97. // Returns 1 if success, 0 if failure
  98. //
  99. int FAR PASCAL HardwareInit (LPDEVICE_INIT lpDI)
  100. {
  101.     BOOL bOK = FALSE;
  102.     
  103.     if (CT_Init ()) {
  104.         CT_SetFrameAddress ((int) (lpDI-> wSegment)); // wants 1-15
  105.         gbInt = (BYTE) CT_SetIRQUsed ((int) lpDI-> bInterrupt); 
  106.         bOK = TRUE;
  107.     }
  108.     return bOK;
  109. }
  110.  
  111. //
  112. // Deinitialize the device. Call once only.
  113. // Returns 1 if success, 0 if failure
  114. //
  115. void FAR PASCAL HardwareFini ()
  116. {
  117.     CT_Fini ();
  118. }
  119.  
  120. //
  121. // Library initialization code.
  122. // Parameters:
  123. //      Our module handle.
  124. //      The heap size from the .def file.
  125. //      The command line.
  126. // Returns:
  127. //      Returns 1 if the initialization was successful and 0 otherwise.
  128. //
  129. int NEAR PASCAL LibMain(HANDLE hModule, WORD wHeapSize, LPSTR lpCmdLine)
  130. {
  131.     DEVICE_INIT devInit;
  132.  
  133.     D1("LibMain");
  134.  
  135. #ifdef DEBUG
  136.     // get debug level - default is 0
  137.     wDebugLevel = GetProfileInt(gszDebug, gszDriverName, 0);
  138. #endif
  139.  
  140.     // save our module handle
  141.     ghModule = hModule;
  142.  
  143.     /* Set Driver entry (usage) count to NULL */
  144.     gwDriverUsage = 0;
  145.     gwCaptureUsage = 0;
  146.     gwDisplayUsage = 0;
  147.     gwVideoInUsage = 0;
  148.     gwVideoOutUsage = 0;
  149.  
  150.     // read system.ini and get the board configuration information.
  151.     GetHardwareSettingsFromINI(&devInit);
  152.  
  153.     // verify address and IRQ
  154.     if ( ! (InitVerifyConfiguration (&devInit) ) )
  155.     {
  156.         D1("hardware is not properly configured!");
  157. //      HardErrorMsgBox( IDS_ERRBADPORT );
  158.     }
  159.     else
  160.     {
  161.         // set the configuration (IRQ and Frame memory address)
  162.         InitSetConfiguration( &devInit );
  163.     }
  164.     // always succeed load! (if config error, we will not Enable...).
  165.     return ( 1 );
  166. }
  167.  
  168.  
  169. //
  170. // Returns DV_ERR_OK if frame memory is writable
  171. //
  172. DWORD FAR PASCAL InitCheckMem( void )
  173. {
  174.     int j;
  175.     LPSTR lpc;
  176.  
  177.     if ((GetWinFlags() & WF_ENHANCED) == 0)
  178.         return DV_ERR_PROTECT_ONLY;       // Only run in enhanced mode
  179.  
  180.       // Why doesn't this work?
  181. //    if (IsBadHugeReadPtr (glpFrameBuffer, 1024L * 1023L))
  182. //        return DV_ERR_MEM_CONFLICT;       // Check to make sure the pointer is valid
  183.  
  184.       // Not all the bits are returned when writing data, so
  185.       // we must mask the returned data
  186.  
  187.       lpc = glpFrameBuffer;
  188.       for (j = 0; j < 100; j++, lpc++) {
  189.         *lpc = 0x0a;
  190.         if ((*lpc & 0x0a) != 0x0a)
  191.           return DV_ERR_MEM_CONFLICT;
  192.       }
  193.  
  194.       return DV_ERR_OK;
  195. }
  196.  
  197.